package com.api.aron.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;

import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * 下一个节点操作者
 * @author YDH
 * CreateTime 2020年9月16日 上午8:54:25
 */
public class TestNextNodeOperater extends BaseBean implements Action{

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestId = requestInfo.getRequestid();
        rs.writeLog("当前流程请求id："+requestId);
        int userid = requestInfo.getRequestManager().getUserId();
        rs.writeLog("当前用户id："+userid);
        int nextNodeId = requestInfo.getRequestManager().getNextNodeid();
        rs.writeLog("下一个节点id"+nextNodeId);
        int str = requestInfo.getRequestManager().getLastoperator();
        rs.writeLog("上一个节点操作者："+str);
        getNextNodeOperator(requestId, nextNodeId);
        return SUCCESS;
    }
    
    public static void getNextNodeOperator(String requestid,int nodeid) {
        RecordSet rs = new RecordSet();
        String[] str = null;
        String sql = "select receivedpersonids,destnodeid,t3.nodename from workflow_requestlog t1 " + 
                "  left join workflow_nodebase t3 on t1.nodeid = t3.id " + 
                "  where  t1.requestid = ? and t1.nodeid =?";
        rs.executeQuery(sql, requestid,nodeid);
        while(rs.next()) {
            String userid =Util.null2String(rs.getString("receivedpersonids"));
            if(!isBlank(userid)) {
                str = userid.split(",");
            }
        }
        rs.writeLog("下一个节点操作者id："+str);
    }
    
    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}
